package com.fbli.controller;

import com.fbli.entity.Result;
import com.fbli.pojo.Knowledge;
import com.fbli.service.KnowledgeService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/knowledge")
public class KnowledgeController {
    @Autowired
    private KnowledgeService knowledgeService;
    @RequestMapping("/selectPage")
    public PageInfo<Knowledge> selectPage(@RequestBody Knowledge knowledge, int pageNum, int pageSize){
       return knowledgeService.selectPage(knowledge,pageNum,pageSize);
    }
    @RequestMapping("/deleteById")
    public void deleteById(long[] ids){
        knowledgeService.deleteById(ids);
    }

    @RequestMapping("/selectById")
    public Knowledge selectById(int id){
        return knowledgeService.selectById(id);
    }

    @RequestMapping("/update")
    public Result update(@RequestBody Knowledge knowledge){
        try {
            knowledgeService.update(knowledge);
            return new Result(true,"成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"异常，失败");
        }
    }
    @RequestMapping("/insert")
    public Result insert(@RequestBody Knowledge addknowledge){
        System.out.println("经过了这里insert");
        try {
            knowledgeService.insert(addknowledge);
            return new Result(true,"成功");
        }catch (Exception e){
            e.printStackTrace();
            return new Result(false,"异常，失败");
        }
    }
}
